using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using CoachingOrganizer.iOS.Controllers.Tools.MoneyCalculation;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;

namespace CoachingOrganizer.iOS.DataSources.Tools.MoneyCalculation
{
    public class ReportPeriodsDataSource : UIPickerViewModel
    {
        private readonly UIPickerView _view;
        private readonly ResultsMoneyCalculationDetailsViewController _controller;
        private readonly MoneyCalculationModel _model;

        public ReportPeriodsDataSource(UIPickerView view, ResultsMoneyCalculationDetailsViewController controller, MoneyCalculationModel model)
        {
            _view = view;
            _controller = controller;
            _model = model;
            model.Report.PeriodReportsChanged += Report_PeriodReportsChanged;
        }

        public override int GetRowsInComponent(UIPickerView picker, int component)
        {
            return _model.Report.PeriodReports == null ? 0 : _model.Report.PeriodReports.Count();
        }

        public override string GetTitle(UIPickerView picker, int row, int component)
        {
            PeriodReportModel periodReportModel = _model.Report.PeriodReports.ElementAt(row);
            return string.Format("{0} - {1}", periodReportModel.StartDate, periodReportModel.FinishDate);
        }

        private void Report_PeriodReportsChanged(object sender, EventArgs e)
        {
            _view.ReloadAllComponents();
        }
    }
}